#pragma once

struct Color {
 byte red;
 byte green;
 byte blue;
 byte alpha;
 inline bool transparent(void) {
  return alpha < 255;
 }
 inline void multiply(void) {
  int r = red;
  int g = green;
  int b = blue;
  int a = alpha;
  red = (r * a) / 255;
  green = (g * a) / 255;
  blue = (b * a) / 255;
  alpha = 255;
 }
 inline Color & operator+=(const Color & other) {
  red += other.red;
  green += other.green;
  blue += other.blue;
 }
 inline operator lword(void) {
  return *(lword *)this;
 }
};

struct MultiColor {
 lword red;
 lword green;
 lword blue;
 lword alpha;
 lword number;
 inline void operator+=(const Color & other) {
  red += other.red;
  green += other.green;
  blue += other.blue;
  alpha += other.alpha;
  ++number;
 }
 inline operator Color(void) { // Returns the average color
  if (number > 1)
   return Color{byte(red / number),byte(green / number),byte(blue / number),byte(alpha / number)};
  else
   return Color{byte(red),byte(green),byte(blue),byte(alpha)};
 }
};
